<template>
  <a-form @submit="handleSubmit" :form="form">
    <a-form-item
      label="角色名"
      :labelCol="labelCol"
      :wrapperCol="wrapperCol"
    >
      <a-input
        v-decorator="['name', {rules: [{ required: true, message: '请输入角色名称' }]}]"
        name="name"
        placeholder="请输入角色名称"/>
    </a-form-item>
    <a-form-item
      label="状态"
      :labelCol="labelCol"
      :wrapperCol="wrapperCol"
    >
      <a-radio-group
        v-decorator="['status', { initialValue: 1 }]">
        <a-radio :value="1">启用</a-radio>
        <a-radio :value="2">禁用</a-radio>
      </a-radio-group>
    </a-form-item>
    <a-form-item
      label="备注"
      :labelCol="labelCol"
      :wrapperCol="wrapperCol"
    >
      <a-textarea
        placeholder="请输入备注"
        :maxLength="200"
        :autoSize="{ minRows: 3, maxRows: 5 }"
        v-decorator="['remark',{rules: [{ required: false, message: '请输入备注' }]}]"
      />
    </a-form-item>
  </a-form>
</template>

<script>
  export default {
    name: 'RoleBaseForm',
    props: {
      roleInfo: {
        type: Object,
        default: () => {
        }
      }
    },
    data () {
      return {
        labelCol: {
          xs: { span: 2 },
          sm: { span: 2 }
        },
        wrapperCol: {
          xs: { span: 8 },
          sm: { span: 8 }
        },

        // form
        form: this.$form.createForm(this)
      }
    },
    watch: {
      roleInfo: function (roleInfo) {
        if (roleInfo.hasOwnProperty('id')) {
          this.form.setFieldsValue({
            name: roleInfo.name,
            status: roleInfo.status,
            remark: roleInfo.remark
          })
        }
      }
    },
    methods: {
      handleSubmit (e) {
        e.preventDefault()
        this.form.validateFields((err, values) => {
          if (!err) {
            this.$notification['error']({
              message: 'Received values of form:',
              description: values
            })
          }
        })
      }
    }
  }
</script>

<style scoped>

</style>
